﻿using System;
using UnityEditor;
using UnityEngine;
using System.Runtime.InteropServices;

namespace hxweditor
{
	public class SkillActionEditor:BaseEditorWindow<SkillActionEditor>
	{
		public static int propId = 0;

		public static float delayTime = 0;

		public static SkillActionEnum type = SkillActionEnum.playSkillAnimation;

        public static AnimationType animation = AnimationType.paobu;

		public static string resourceName = "ResourceName";

		SkillActionEditor()
		{
			this.titleContent = new GUIContent("技能属性编辑器");
		}


		void OnGUI ()
		{

			propId = ShowInputInt ("唯一PropID:", propId);

			ShowSpaceLine (1);

			type = (SkillActionEnum)ShowPopUp ("类型:", type);

			ShowSpaceLine (1);

			delayTime = ShowInputFloat ("延时:", delayTime);

			ShowSpaceLine (1);

			if (type == SkillActionEnum.playGetHitAnimation || type == SkillActionEnum.playSkillAnimation) {
                animation = (AnimationType)ShowPopUp("动作名:", animation, null);
			} else {
				resourceName = ShowInputString ("资源名:", resourceName);
				if (ShowButton ("从文件当中选择")) {
					OpenFileName file = WindowDll.GetDefault ();
					if (WindowDll.GetOpenFileName (file)) {
						string fileName = FileTool.GetFileName (file.fileTitle);
						if (fileName != "")
							resourceName = fileName;
					}
				}
			}

			ShowSpaceLine (2);
			if (ShowButton ("增加")) {
				AddActionVo ();
			}

			ShowSpaceLine (1);
			if (ShowButton ("删除")) {
				RemoveProp ();
			}
		}

		private static void AddActionVo ()
		{
            if(propId == 0)
            {
                ShowAlert("属性ID不能为0，注意属性ID不能一样!");
                return;
            }
            SkillActionVo vo = SkillActionVo.Creat(propId,type,delayTime,animation,resourceName);
			SkillEffectEditor.SetActionVo (vo);
			CloseWindow ();
		}

		private static void RemoveProp ()
		{
			if (propId > 0 && SkillEffectEditor.IsOpen) {
				SkillEffectEditor.RemoveActionVo (propId);
			}
			CloseWindow ();
		}

		public static void SetActionVo (SkillActionVo vo)
		{
			propId = vo.propId;
			delayTime = vo.delayTime;
            type = (SkillActionEnum)vo.type;
            animation = (AnimationType)vo.animation;
			resourceName = vo.resourceName;
			FocusThis ();
		}

	}
}

